{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Fusion_system.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/EriProject/Multimodal_Biometrics/blob/master/Fusion_system.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nwglxhJtpNcx",
        "colab_type": "code",
        "outputId": "e7b002b0-7f98-4e05-e10b-dafd59a1b331",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "from keras.applications import ResNet50\n",
        "from keras.models import Sequential\n",
        "from keras.applications import imagenet_utils\n",
        "from keras.layers.core import Dense, Flatten, Dropout\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import tensorflow\n",
        "from tensorflow.keras.models import model_from_json\n",
        "import numpy as np\n",
        "from sklearn.metrics import confusion_matrix \n",
        "from keras.applications.resnet50 import preprocess_input\n",
        "from keras.preprocessing.image import ImageDataGenerator"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Using TensorFlow backend.\n"
          ],
          "name": "stderr"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NwoolWlQChFi",
        "colab_type": "code",
        "outputId": "246f4803-cd82-4865-a06c-c0884959be3b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 124
        }
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5RhTPyn_rQCF",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def load_model_and_weights_face():\n",
        "    print(\"[INFO] Loading face model and its weights...\")\n",
        "    # Loading and using saved model steps\n",
        "    # load json and create model\n",
        "    js_file_face= open('/content/drive/My Drive/Final_Fusion/SAVED MODELS/Face Model/model_1.json', 'r')\n",
        "    loaded_model_json_face = js_file_face.read()\n",
        "    js_file_face.close()\n",
        "    loaded_model_face= model_from_json(loaded_model_json_face)\n",
        "    # load weights into new loaded model\n",
        "    loaded_model_face.load_weights('/content/drive/My Drive/Final_Fusion/SAVED MODELS/Face Model/second_face2.h5')\n",
        "    print(\"Loaded face model with its weights from drive\")\n",
        "    return loaded_model_face\n",
        "\n",
        "\n",
        "def load_model_and_weights_iris():\n",
        "    print(\"[INFO] Loading Iris model and its weights...\")\n",
        "    # Loading and using saved model steps\n",
        "    # load json and create model\n",
        "    js_file_iris= open('/content/drive/My Drive/Final_Fusion/SAVED MODELS/Iris Model/model_1.json', 'r')\n",
        "    loaded_model_json_iris = js_file_iris.read()\n",
        "    js_file_iris.close()\n",
        "    loaded_model_iris= model_from_json(loaded_model_json_iris)\n",
        "    # load weights into new loaded model\n",
        "    loaded_model_iris.load_weights('/content/drive/My Drive/Final_Fusion/SAVED MODELS/Iris Model/adam_50epoch_iris.h5')\n",
        "    # loaded_model_iris.load_weights('/content/drive/My Drive/Final_Fusion/SAVED MODELS/Iris Model/best_iris.h5')\n",
        "    print(\"Loaded Iris model with its weights from drive\")\n",
        "    return loaded_model_iris\n",
        "\n",
        "\n",
        "def load_model_and_weights_ecg():\n",
        "    print(\"[INFO] Loading face model and its weights...\")\n",
        "    # Loading and using saved model steps\n",
        "    # load json and create model\n",
        "    js_file_ecg= open('/content/drive/My Drive/Final_Fusion/SAVED MODELS/ECG Model/model_1.json', 'r')\n",
        "    loaded_model_json_ecg = js_file_ecg.read()\n",
        "    js_file_ecg.close()\n",
        "    loaded_model_ecg= model_from_json(loaded_model_json_ecg)\n",
        "    # load weights into new loaded model\n",
        "    loaded_model_ecg.load_weights('/content/drive/My Drive/Final_Fusion/SAVED MODELS/ECG Model/ecg_sgd_last.h5')\n",
        "    print(\"Loaded face model with its weights from drive\")\n",
        "    return loaded_model_ecg"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ezco5s4lYUBj",
        "colab_type": "code",
        "outputId": "c4543504-2cd3-490d-dcb8-ef9e6b601635",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "# load the model and weights from directory\n",
        "loaded_model_iris=load_model_and_weights_iris()\n",
        "loaded_model_face=load_model_and_weights_face()\n",
        "loaded_model_ecg=load_model_and_weights_ecg()"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[INFO] Loading Iris model and its weights...\n",
            "Loaded Iris model with its weights from drive\n",
            "[INFO] Loading face model and its weights...\n",
            "Loaded face model with its weights from drive\n",
            "[INFO] Loading face model and its weights...\n",
            "Loaded face model with its weights from drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IPrpkTRkP3HJ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        },
        "outputId": "99de3d6e-2b61-4c7e-8483-1a2c5fa29a91"
      },
      "source": [
        "test_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)\n",
        "image_size=224\n",
        "\n",
        "# Iris TEST DATA\n",
        "test_generator_iris = test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Iris_Data/Test',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "\n",
        "test_generator_random_iris=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Iris_Data/Iris_Outsider',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "\n",
        "# Face TEST DATA\n",
        "\n",
        "test_generator_face= test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Face_Data/Validation',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "\n",
        "test_generator_random_face=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Face_Data/Face_Outsider',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "\n",
        "# ECG TEST DATA\n",
        "\n",
        "test_generator_ecg = test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/ECG_Data/Test',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "# ECG Random\n",
        "test_generator_random_ecg=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/ECG_Data/ECG_Outsider',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Found 40 images belonging to 40 classes.\n",
            "Found 40 images belonging to 1 classes.\n",
            "Found 80 images belonging to 40 classes.\n",
            "Found 80 images belonging to 1 classes.\n",
            "Found 80 images belonging to 40 classes.\n",
            "Found 80 images belonging to 1 classes.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eBOZiNteiVKG",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 89
        },
        "outputId": "649c02c3-520f-44a5-a5e9-76e0d4c0df81"
      },
      "source": [
        "# prediction (person number)  to name converter list for face\n",
        "face_list=[]\n",
        "ecg_list=[]\n",
        "iris_list=[]\n",
        "# display(test_generator_iris.class_indices)\n",
        "for x in test_generator_face.class_indices:\n",
        "  face_list.append(x)\n",
        "for x in test_generator_iris.class_indices:\n",
        "  iris_list.append(x)\n",
        "for x in test_generator_ecg.class_indices:\n",
        "  ecg_list.append(x)\n",
        "print(\"Face: \",test_generator_face.class_indices)\n",
        "print(\"Iris: \",test_generator_iris.class_indices)\n",
        "print(\"Ecg: \",test_generator_ecg.class_indices)\n"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Face:  {'adhast': 0, 'ajbake': 1, 'apapou': 2, 'apdavi': 3, 'ardper': 4, 'awjsud': 5, 'boylee': 6, 'bschap': 7, 'cadugd': 8, 'cdlarg': 9, 'cfloro': 10, 'cladam': 11, 'cywan': 12, 'dakram': 13, 'damvo': 14, 'darda': 15, 'dfhodd': 16, 'dgemen': 17, 'gsmall': 18, 'gstamo': 19, 'gsvird': 20, 'hcarpe': 21, 'howar': 22, 'hsgrim': 23, 'ijfran': 24, 'isbald': 25, 'jbierl': 26, 'jross': 27, 'jserai': 28, 'jshea': 29, 'kbartl': 30, 'kmbald': 31, 'kouri': 32, 'labenm': 33, 'ldgodd': 34, 'lidov': 35, 'llambr': 36, 'matth': 37, 'mdchud': 38, 'mizli': 39}\n",
            "Iris:  {'Person_01': 0, 'Person_02': 1, 'Person_03': 2, 'Person_04': 3, 'Person_05': 4, 'Person_06': 5, 'Person_07': 6, 'Person_08': 7, 'Person_09': 8, 'Person_10': 9, 'Person_11': 10, 'Person_12': 11, 'Person_13': 12, 'Person_14': 13, 'Person_15': 14, 'Person_16': 15, 'Person_17': 16, 'Person_18': 17, 'Person_19': 18, 'Person_20': 19, 'Person_21': 20, 'Person_22': 21, 'Person_23': 22, 'Person_24': 23, 'Person_25': 24, 'Person_26': 25, 'Person_27': 26, 'Person_28': 27, 'Person_29': 28, 'Person_30': 29, 'Person_31': 30, 'Person_32': 31, 'Person_33': 32, 'Person_34': 33, 'Person_35': 34, 'Person_36': 35, 'Person_37': 36, 'Person_38': 37, 'Person_39': 38, 'Person_40': 39}\n",
            "Ecg:  {'Person_01': 0, 'Person_02': 1, 'Person_03': 2, 'Person_04': 3, 'Person_05': 4, 'Person_06': 5, 'Person_07': 6, 'Person_08': 7, 'Person_09': 8, 'Person_10': 9, 'Person_11': 10, 'Person_12': 11, 'Person_13': 12, 'Person_14': 13, 'Person_15': 14, 'Person_16': 15, 'Person_17': 16, 'Person_18': 17, 'Person_19': 18, 'Person_20': 19, 'Person_21': 20, 'Person_22': 21, 'Person_23': 22, 'Person_24': 23, 'Person_25': 24, 'Person_26': 25, 'Person_27': 26, 'Person_28': 27, 'Person_29': 28, 'Person_30': 29, 'Person_31': 30, 'Person_32': 31, 'Person_33': 32, 'Person_34': 33, 'Person_35': 34, 'Person_36': 35, 'Person_37': 36, 'Person_38': 37, 'Person_39': 38, 'Person_40': 39}\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-O5FYh0UuR74",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 191
        },
        "outputId": "419f46a7-499b-406b-a2cb-52c2857bc525"
      },
      "source": [
        " print(\"Loaded model with its weights from drive\")\n",
        "iris_pred = loaded_model_iris.predict_generator(test_generator_iris, steps = len(test_generator_iris), verbose = 1)\n",
        "face_pred = loaded_model_face.predict_generator(test_generator_face, steps = len(test_generator_face), verbose = 1)\n",
        "ecg_pred = loaded_model_ecg.predict_generator(test_generator_ecg, steps = len(test_generator_ecg), verbose = 1)\n",
        "\n",
        "iris_random_pred=loaded_model_iris.predict_generator(test_generator_random_iris, steps = len(test_generator_random_iris), verbose = 1)\n",
        "face_random_pred=loaded_model_face.predict_generator(test_generator_random_face, steps = len(test_generator_random_face), verbose = 1)\n",
        "ecg_random_pred=loaded_model_ecg.predict_generator(test_generator_random_ecg, steps = len(test_generator_random_ecg), verbose = 1)\n"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Loaded model with its weights from drive\n",
            "WARNING:tensorflow:From <ipython-input-7-18f38b69f269>:2: Model.predict_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.\n",
            "Instructions for updating:\n",
            "Please use Model.predict, which supports generators.\n",
            "40/40 [==============================] - 11s 281ms/step\n",
            "80/80 [==============================] - 22s 273ms/step\n",
            "80/80 [==============================] - 22s 274ms/step\n",
            "40/40 [==============================] - 11s 286ms/step\n",
            "80/80 [==============================] - 21s 266ms/step\n",
            "80/80 [==============================] - 21s 265ms/step\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TFqyjonKkOYv",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        },
        "outputId": "d712ad07-6b8a-4214-85fb-86252a0c58b9"
      },
      "source": [
        "#40 genuine Iris\n",
        "test_generator_fused_iris=test_datagen.flow_from_directory(\n",
        "    directory = '/content/drive/My Drive/Final_Fusion/Iris_Data/Test',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 40,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "#40 imposter Iris\n",
        "test_generator_frandom_iris=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Iris_Data/Iris_Outsider',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "#40 genuine face\n",
        "test_generator_fused_face=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Face_Data/Test',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 40,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "#40 imposter face\n",
        "test_generator_frandom_face=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/Face_Data/face_outsider_40',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "#40 genuine  ECG\n",
        "test_generator_fused_ecg=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/ECG_Data/test-forty',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 40,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "# 40 imposter ECG \n",
        "test_generator_frandom_ecg=test_datagen.flow_from_directory(\n",
        "    directory ='/content/drive/My Drive/Final_Fusion/ECG_Data/ECG_Outsider_40',\n",
        "    target_size = (image_size, image_size),\n",
        "    batch_size = 1,\n",
        "    class_mode = None,\n",
        "    shuffle = False,\n",
        "    seed = 123\n",
        ")\n",
        "#'/content/drive/My Drive/Final_Fusion/Fused_test/ECG'\n",
        "\n"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Found 40 images belonging to 40 classes.\n",
            "Found 40 images belonging to 1 classes.\n",
            "Found 40 images belonging to 40 classes.\n",
            "Found 40 images belonging to 1 classes.\n",
            "Found 40 images belonging to 40 classes.\n",
            "Found 40 images belonging to 1 classes.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "24gvKDufCTos",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        },
        "outputId": "194779b9-fbf3-4462-abfe-9c8534f76eb1"
      },
      "source": [
        "# Single person predicitions\n",
        "fused_iris_pred = loaded_model_iris.predict_generator(test_generator_fused_iris, steps = len(test_generator_fused_iris), verbose = 1)\n",
        "fused_face_pred = loaded_model_face.predict_generator(test_generator_fused_face, steps = len(test_generator_fused_face), verbose = 1)\n",
        "fused_ecg_pred = loaded_model_ecg.predict_generator(test_generator_fused_ecg, steps = len(test_generator_fused_ecg), verbose = 1)\n",
        "\n",
        "fused_iris_pred_rand = loaded_model_iris.predict_generator(test_generator_frandom_iris, steps = len(test_generator_frandom_iris), verbose = 1)\n",
        "fused_face_pred_rand = loaded_model_face.predict_generator(test_generator_frandom_face, steps = len(test_generator_frandom_face), verbose = 1)\n",
        "fused_ecg_pred_rand = loaded_model_ecg.predict_generator(test_generator_frandom_ecg, steps = len(test_generator_frandom_ecg), verbose = 1)\n",
        "\n",
        "\n",
        "predicted_iris=np.argmax(fused_iris_pred, axis = 1)\n",
        "predicted_face=np.argmax(fused_face_pred, axis = 1)\n",
        "predicted_ecg=np.argmax(fused_ecg_pred, axis = 1)\n",
        "\n",
        "predicted_iris_rand=np.argmax(fused_iris_pred_rand, axis = 1)\n",
        "predicted_face_rand=np.argmax(fused_face_pred_rand, axis = 1)\n",
        "predicted_ecg_rand=np.argmax(fused_ecg_pred_rand, axis = 1)\n",
        "\n",
        "iris_confidence=[]\n",
        "iris_confidence_rand=[]\n",
        "iris_label=[]\n",
        "iris_label_rand=[]\n",
        "face_confidence=[] \n",
        "face_confidence_rand=[] \n",
        "face_label_rand =[]\n",
        "face_label =[]\n",
        "ecg_confidence=[]\n",
        "ecg_confidence_rand=[]\n",
        "ecg_label=[]\n",
        "ecg_label_rand=[]\n",
        "\n",
        "for i in range(0,40):\n",
        "  iris_confidence.append(fused_iris_pred[i][predicted_iris[i]])\n",
        "  iris_confidence_rand.append(fused_iris_pred_rand[i][predicted_iris_rand[i]])\n",
        "\n",
        "  iris_label.append(predicted_iris[i]+1)\n",
        "  iris_label_rand.append(predicted_iris_rand[i]+1)\n",
        "\n",
        "  face_confidence.append(fused_face_pred[i][predicted_face[i]])\n",
        "  face_confidence_rand.append(fused_face_pred_rand[i][predicted_face_rand[i]])\n",
        "\n",
        "  face_label.append(predicted_face[i]+1)\n",
        "  face_label_rand.append(predicted_face_rand[i]+1)\n",
        "\n",
        "  ecg_confidence.append(fused_ecg_pred[i][predicted_ecg[i]])\n",
        "  ecg_confidence_rand.append(fused_ecg_pred_rand[i][predicted_ecg_rand[i]])\n",
        "  \n",
        "  ecg_label.append(predicted_ecg[i]+1)\n",
        "  ecg_label_rand.append(predicted_ecg_rand[i]+1)\n",
        "   \n",
        "\n",
        "  # print(\"From Iris: Person_\",iris_label_rand[i])\n",
        "  # print(\"Confidence score:\",iris_confidence_rand[i])\n",
        "  # print(\"From Face: Person_\",face_label_rand[i])\n",
        "  # print(\"Confidence score:\",face_confidence_rand[i])\n",
        "  # print(\"From ECG: Person_\",ecg_label_rand[i])\n",
        "  # print(\"Confidence score:\",ecg_confidence_rand[i])\n",
        "  # print(\"////////////////////////////////////////////////////////////////////////////////////////\")\n",
        "\n",
        "\n",
        "\n"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1/1 [==============================] - 0s 1ms/step\n",
            "1/1 [==============================] - 0s 2ms/step\n",
            "1/1 [==============================] - 0s 1ms/step\n",
            "40/40 [==============================] - 0s 10ms/step\n",
            "40/40 [==============================] - 9s 222ms/step\n",
            "40/40 [==============================] - 9s 235ms/step\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K84GIw8Hwo_g",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 72
        },
        "outputId": "bfd3a834-939f-475b-d066-167de1279947"
      },
      "source": [
        "import numpy as np\n",
        "h = 40\n",
        "iris_score_vector = [[0 for x in range(h)] for y in range(h)] \n",
        "face_score_vector = [[0 for x in range(h)] for y in range(h)] \n",
        "ecg_score_vector =  [[0 for x in range(h)] for y in range(h)] \n",
        "fusion_score= [[0 for x in range(h)] for y in range(h)] \n",
        "max_confe=[]\n",
        "fusion_confidence=[]\n",
        "fusion_person=[]\n",
        "weight_vector=[0.474,0.474,0.052]    #iris->index=0 , face-> index=1 , ecg-> index=2\n",
        "for i in range (0,40):\n",
        "     iris_score_vector[i]=fused_iris_pred[i]*weight_vector[0]\n",
        "     face_score_vector[i]=fused_face_pred[i]*weight_vector[1]\n",
        "     ecg_score_vector[i]=fused_ecg_pred[i]*weight_vector[2]\n",
        "     for j in range (0,40):\n",
        "          fusion_score[i][j]= iris_score_vector[i][j] + face_score_vector[i][j] + ecg_score_vector[i][j]\n",
        "     max_confe.append(np.argmax( fusion_score[i]))\n",
        "     fusion_confidence.append(fusion_score[i][max_confe[i]])\n",
        "     fusion_person.append( max_confe[i] + 1)\n",
        "print( fusion_confidence)\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "iris_score_vector_rand = [[0 for x in range(h)] for y in range(h)] \n",
        "face_score_vector_rand = [[0 for x in range(h)] for y in range(h)] \n",
        "ecg_score_vector_rand =  [[0 for x in range(h)] for y in range(h)] \n",
        "fusion_score_rand= [[0 for x in range(h)] for y in range(h)] \n",
        "max_confe_rand=[]\n",
        "fusion_confidence_rand=[]\n",
        "fusion_person_rand=[]\n",
        "for i in range (0,40):\n",
        "     iris_score_vector_rand[i]=fused_iris_pred_rand[i]*weight_vector[0]\n",
        "     face_score_vector_rand[i]=fused_face_pred_rand[i]*weight_vector[1]\n",
        "     ecg_score_vector_rand[i]=fused_ecg_pred_rand[i]*weight_vector[2]\n",
        "     for j in range (0,40):\n",
        "          fusion_score_rand[i][j]= iris_score_vector_rand[i][j] + face_score_vector_rand[i][j] + ecg_score_vector_rand[i][j]\n",
        "     max_confe_rand.append(np.argmax( fusion_score_rand[i]))\n",
        "     fusion_confidence_rand.append(fusion_score_rand[i][max_confe_rand[i]])\n",
        "     fusion_person_rand.append( max_confe_rand[i] + 1)\n",
        "print( \"Random people: \",fusion_confidence_rand)\n",
        "\n",
        "    \n",
        "    # for j in range (0,40):\n",
        "    #   fusion_score[i][j]=a[j] + b[j] + c[j]\n",
        "    # max_confe= np.argmax( fusion_score[i])\n",
        "\n",
        "    # fusion_confidence=fusion_score[i][max_confe]\n",
        "    # \n",
        "    # print(\"Predicted: Person_\",max_confe + 1)\n",
        "    # print(\"confidence score: \",fusion_confidence)\n",
        "\n"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[0.99203634, 0.955346, 0.9645418, 0.9895861, 0.8751131, 0.98808086, 0.97879803, 0.97067696, 0.97480726, 0.99406826, 0.9825875, 0.98644996, 0.9931847, 0.9888304, 0.98380566, 0.96979666, 0.98152757, 0.9925329, 0.94772714, 0.9739908, 0.9824254, 0.9772979, 0.98352575, 0.97076255, 0.99338657, 0.97566366, 0.96493393, 0.9721219, 0.95898914, 0.9196116, 0.98592323, 0.9878112, 0.9822985, 0.98279375, 0.9566577, 0.9815578, 0.96930325, 0.98706406, 0.9903061, 0.9771472]\n",
            "Random people:  [0.115467474, 0.07256569, 0.09049175, 0.16132128, 0.2682187, 0.30513847, 0.1244552, 0.18167469, 0.13254371, 0.13532062, 0.12866476, 0.07500989, 0.21077305, 0.104004204, 0.1606412, 0.07802845, 0.10011834, 0.26807225, 0.17596063, 0.14683005, 0.08849431, 0.12815662, 0.16519316, 0.12194461, 0.10212324, 0.0966276, 0.09538069, 0.10819087, 0.12751673, 0.0899367, 0.09012369, 0.09885004, 0.23315491, 0.12744682, 0.19330782, 0.10079855, 0.15273349, 0.10831086, 0.09133722, 0.1572733]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "q-yVk49cJMYl",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# SAVE labels and scores to train a classifier\n",
        "# order ---> actual_label,iris_score,iris_label,face_score,face_label,ecg_score,ecg_label,Weighted_score,Weighted_label \n",
        "\n",
        "Alabels=[]\n",
        "total_array = [[0 for x in range(9)] for y in range(80)] \n",
        "n=0\n",
        "for m in range (1,41):\n",
        "   Alabels.append(m)\n",
        "   total_array[m-1][0]=m\n",
        "   total_array[m+40-1][0]=0\n",
        "\n",
        "   total_array[m-1][1]=iris_confidence[m-1]\n",
        "   total_array[m+40-1][1]=iris_confidence_rand[m-1]\n",
        "\n",
        "   total_array[m-1][2]=iris_label[m-1]\n",
        "   total_array[m+40-1][2]=iris_label_rand[m-1]\n",
        "\n",
        "   total_array[m-1][3]=face_confidence[m-1]\n",
        "   total_array[m+40-1][3]=face_confidence_rand[m-1]\n",
        "\n",
        "   total_array[m-1][4]=face_label[m-1]\n",
        "   total_array[m+40-1][4]=face_label_rand[m-1]\n",
        "\n",
        "   total_array[m-1][5]=ecg_confidence[m-1]\n",
        "   total_array[m+40-1][5]=ecg_confidence_rand[m-1]\n",
        "\n",
        "   total_array[m-1][6]=ecg_label[m-1]\n",
        "   total_array[m+40-1][6]=ecg_label_rand[m-1]\n",
        "\n",
        "   total_array[m-1][7]=fusion_confidence[m-1]\n",
        "   total_array[m+40-1][7]=fusion_confidence_rand[m-1]\n",
        "\n",
        "   total_array[m-1][8]=fusion_person[m-1]\n",
        "   total_array[m+40-1][8]=fusion_person_rand[m-1]\n",
        "\n",
        "\n",
        "total_narray=np.asarray(total_array)\n",
        "# order -- Actual label, Si(score iris),Li (label iris),Sf,Lf,Se,Le,Ws(Weighted Sum), WL(weigted label)\n",
        "with open('outputfile.csv', 'ab') as f:\n",
        "  f.write(b'actual_label,iris_score,iris_label,face_score,face_label,ecg_score,ecg_label,Weighted_score,Weighted_label\\n')\n",
        "  np.savetxt(f, total_narray, fmt=('%.i,%.18e,%.i,%.18e,%.i,%.18e,%.i,%.18e,%.i'),delimiter=',')\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TLsJxTKNCMnn",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "7ebb02a2-953b-4e3a-bc48-a8c63d314ee8"
      },
      "source": [
        "# Compare with treshold\n",
        "iris_EER = 0.60   # Between 32.8-33.3 -----> 50--75\n",
        "face_EER= 0.75  # Between 59-74------> 65-75\n",
        "ECG_EER=0.87   # Between 85------> 87\n",
        "fusion_threshold=0.85\n",
        "HighConfidence= 0.9\n",
        "HighConfidenceECG=0.95\n",
        "#  iris_label ----> label given by iris model\n",
        "#  face_label ----> label given by face model\n",
        "\n",
        "\n",
        "#  Decision tree based on weighted sum, Threshold of the subsystems, and EER\n",
        "# Checking the Genuine users\n",
        "for i in range (0,40):\n",
        "    if(fusion_confidence[i]<0.50):\n",
        "      print(\"The person is not identified\")\n",
        "    else:\n",
        "      if(fusion_confidence[i]>fusion_threshold):\n",
        "        print(\"The person is identified as : Person_\",fusion_person[i]) #add the corrosponding name\n",
        "      else:\n",
        "        if(iris_confidence[i]<iris_EER):\n",
        "          if(face_confidence[i]>HighConfidence and ecg_confidence[i]>HighConfidenceECG):\n",
        "            print(\"The person is identified as : Person_\",fusion_person[i])#add the corrosponding name\n",
        "          else:\n",
        "            print(\"The person is not identified iris < EER:\",i,iris_confidence[i])\n",
        "        else:\n",
        "          if(face_confidence[i]<face_EER):\n",
        "            if(iris_confidence[i]>HighConfidence and ecg_confidence[i]>HighConfidenceECG):\n",
        "              print(\"The person is identified as : Person_\",fusion_person[i])#add the corrosponding name\n",
        "            elif(ecg_confidence[i]<ECG_EER):\n",
        "              if(iris_confidence[i]>HighConfidence and face_confidence[i]>HighConfidence):\n",
        "                print(\"The person is identified as : Person_\",fusion_person[i])#add the corrosponding name\n",
        "              else:\n",
        "                print(\"The person is not identified\")\n",
        "          else:\n",
        "            print(\"The person is identified as : Person_\",fusion_person[i]) #add the corrosponding name\n",
        "    print(\"////////////////////////////////////////////////////////////////////////////////////////\")\n"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "The person is identified as : Person_ 1\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 2\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 3\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 4\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 5\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 6\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 7\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 8\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 9\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 10\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 11\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 12\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 13\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 14\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 15\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 16\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 17\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 18\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 19\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 20\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 21\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 22\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 23\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 24\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 25\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 26\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 27\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 28\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 29\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 30\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 31\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 32\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 33\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 34\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 35\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 36\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 37\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 38\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 39\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is identified as : Person_ 40\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0-GHy1JO4QAA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "40604452-8a22-44e3-9f33-a1965be4c597"
      },
      "source": [
        "\n",
        "#  Decision tree based on weighted sum, Threshold of the subsystems, and EER\n",
        "# Checking the Imposters \n",
        "for i in range (0,40):\n",
        "    if(fusion_confidence_rand[i]<0.50):\n",
        "      print(\"The person is not identified\")\n",
        "    else:\n",
        "      if(fusion_confidence_rand[i]>fusion_threshold):\n",
        "        print(\"The person is identified as : Person_\",fusion_person_rand[i]) #add the corrosponding name\n",
        "      else:\n",
        "        print(\"The person is not identified\")\n",
        "  \n",
        "      if(iris_confidence_rand[i]<iris_EER):\n",
        "        if(face_confidence_rand[i]>HighConfidence and ecg_confidence_rand[i]>HighConfidenceECG):\n",
        "          print(\"The person is identified as : Person_\",fusion_person_rand[i])#add the corrosponding name\n",
        "        else:\n",
        "          print(\"The person is not identified iris < EER:\",i,iris_confidence_rand[i])\n",
        "      else:\n",
        "        if(face_confidence_rand[i]<face_EER):\n",
        "          if(iris_confidence_rand[i]>HighConfidence and ecg_confidence_rand[i]>HighConfidenceECG):\n",
        "            print(\"The person is identified as : Person_\",fusion_person_rand[i])#add the corrosponding name\n",
        "          elif(ecg_confidence_rand[i]<ECG_EER):\n",
        "            if(iris_confidence_rand[i]>HighConfidence and face_confidence_rand[i]>HighConfidence):\n",
        "              print(\"The person is identified as : Person_\",fusion_person_rand[i])#add the corrosponding name\n",
        "            else:\n",
        "              print(\"The person is not identified\")\n",
        "        else:\n",
        "          print(\"The person is identified as : Person_\",fusion_person_rand[i]) #add the corrosponding name\n",
        "    print(\"////////////////////////////////////////////////////////////////////////////////////////\")"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n",
            "The person is not identified\n",
            "////////////////////////////////////////////////////////////////////////////////////////\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "V-7M_tCyRn8Q",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "tresh=[]\n",
        "percent=[]\n",
        "treshold=0\n",
        "while  treshold <100:\n",
        "    accepted_reg=0\n",
        "    for registered_index in iris_pred:\n",
        "      counter_reg=0\n",
        "      array_reg=np.array([0.0])\n",
        "      max_confidence_reg = array_reg.astype(type('float32', (float,), {}))\n",
        "      max_confIndex_reg=0\n",
        "      for j in registered_index:\n",
        "        if (j > max_confidence_reg):\n",
        "          max_confidence_reg=j\n",
        "          max_confIndex_reg=counter_reg\n",
        "        counter_reg=counter_reg+1\n",
        "      if(max_confidence_reg > treshold*0.01):\n",
        "        accepted_reg+=1\n",
        "    tresh.append(treshold)\n",
        "    percent.append((40-accepted_reg)/40)\n",
        "   # print(\"rejected folks: \",treshold,40-accepted_reg)\n",
        "    treshold+=0.01\n",
        "\n",
        "print(\"percent\",len(percent))\n",
        "tresh_imp=[]\n",
        "percent_imp=[]\n",
        "treshold_imp=0\n",
        "while  treshold_imp <100:\n",
        "    accepted_imp=0\n",
        "    for imp_index in iris_random_pred:\n",
        "      counter_imp=0\n",
        "      array_imp=np.array([0.0])\n",
        "      max_confidence_imp = array_imp.astype(type('float32', (float,), {}))\n",
        "      max_confIndex_imp=0\n",
        "      for j in imp_index:\n",
        "        if (j > max_confidence_imp):\n",
        "          max_confidence_imp=j\n",
        "          max_confIndex_imp=counter_imp\n",
        "        counter_imp+=1\n",
        "      if(max_confidence_imp > treshold_imp*0.01):\n",
        "        accepted_imp+=1\n",
        "    tresh_imp.append(treshold_imp)\n",
        "    percent_imp.append((accepted_imp)/40)\n",
        "    #print(\"accepted impoters: \",treshold_imp,accepted_imp)\n",
        "    treshold_imp+=0.01\n",
        "print(\"percent\",len(percent_imp))\n",
        "equal_tresh=[]\n",
        "equal_percent=[]\n",
        "for i in range(0,len(tresh)):\n",
        "  if (percent_imp[i] == percent[i]):\n",
        "     equal_tresh.append(tresh_imp[i])\n",
        "     equal_percent.append(percent_imp[i])\n",
        "\n",
        "print('Equal Threshod: ',equal_tresh[0],equal_tresh[-1])\n",
        "print('Equal Error Rate: ',equal_percent[0])\n",
        "plt.plot(tresh,percent)\n",
        "plt.plot(tresh_imp,percent_imp)\n",
        "plt.plot(equal_tresh,equal_percent)\n",
        "plt.title('Error Rate')  \n",
        "plt.ylabel('percentage')  \n",
        "plt.xlabel('treshold level')  \n",
        "plt.legend(['FRR', 'FAR','EER']) \n",
        "plt.show()\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Tc8LQZJajPVA",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "tresh_face=[]\n",
        "percent_face=[]\n",
        "treshold_face=0\n",
        "while  treshold_face <100:\n",
        "    accepted_reg_face=0\n",
        "    for  reg_index_face in face_pred:\n",
        "      counter_reg_face=0\n",
        "      array_reg_face=np.array([0.0])\n",
        "      max_confidence_reg_face = array_reg_face.astype(type('float32', (float,), {}))\n",
        "      max_confIndex_reg_face=0\n",
        "      for j in  reg_index_face:\n",
        "        if (j > max_confidence_reg_face):\n",
        "          max_confidence_reg_face=j\n",
        "          max_confIndex_reg_face= counter_reg_face\n",
        "        counter_reg_face= counter_reg_face+1\n",
        "      if(max_confidence_reg_face > treshold_face*0.01):\n",
        "        accepted_reg_face+=1\n",
        "    tresh_face.append(treshold_face)\n",
        "    percent_face.append((80-accepted_reg_face)/80)\n",
        "   # print(\"rejected folks: \",treshold_face,40-accepted_reg)\n",
        "    treshold_face+=0.01\n",
        "\n",
        "\n",
        "tresh_imp_face=[]\n",
        "percent_imp_face=[]\n",
        "treshold_imp_face=0\n",
        "while  treshold_imp_face <100:\n",
        "    accepted_imp_face=0\n",
        "    for imp_index_face in face_random_pred:\n",
        "      counter_imp_face=0\n",
        "      array_imp_face=np.array([0.0])\n",
        "      max_confidence_imp_face = array_imp_face.astype(type('float32', (float,), {}))\n",
        "      max_confIndex_imp_face=0\n",
        "      for j in imp_index_face:\n",
        "        if (j > max_confidence_imp_face):\n",
        "          max_confidence_imp_face=j\n",
        "          max_confIndex_imp_face=counter_imp_face\n",
        "        counter_imp_face+=1\n",
        "      if(max_confidence_imp_face > treshold_imp_face*0.01):\n",
        "        accepted_imp_face+=1\n",
        "    tresh_imp_face.append(treshold_imp_face)\n",
        "    percent_imp_face.append((accepted_imp_face)/80)\n",
        "    #print(\"accepted impoters: \",treshold_imp,accepted_imp)\n",
        "    treshold_imp_face+=0.01\n",
        "\n",
        "equal_tresh_face=[]\n",
        "equal_percent_face=[]\n",
        "for i in range(0,len(tresh_imp_face)):\n",
        "  if (percent_imp_face[i] == percent_face[i]):\n",
        "     equal_tresh_face.append(tresh_imp_face[i])\n",
        "     equal_percent_face.append(percent_imp_face[i])\n",
        "\n",
        "print('Equal Threshod: ',equal_tresh_face[0],equal_tresh_face[-1])\n",
        "print('Equal Error Rate: ',equal_percent_face[0])\n",
        "plt.plot(tresh_face,percent_face)\n",
        "plt.plot(tresh_imp_face,percent_imp_face)\n",
        "plt.plot(equal_tresh_face,equal_percent_face)\n",
        "plt.title('Error Rate Face')  \n",
        "plt.ylabel('percentage')  \n",
        "plt.xlabel('treshold level')  \n",
        "plt.legend(['FRR', 'FAR','EER']) \n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ab52iPfzDyGv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# finding the number of rejected subjects from the registered ones\n",
        "# False Rejection Rate\n",
        "\n",
        "ecg_tresh=[]\n",
        "ecg_percent=[]\n",
        "ecg_treshold=0\n",
        "while  ecg_treshold <100:\n",
        "    ecg_accepted_reg=0\n",
        "    for ecg_registered_index in ecg_pred:\n",
        "      ecg_counter_reg=0\n",
        "      ecg_array_reg=np.array([0.0])\n",
        "      ecg_max_confidence_reg = array_reg.astype(type('float32', (float,), {}))\n",
        "      ecg_max_confIndex_reg=0\n",
        "      for j in ecg_registered_index:\n",
        "        if (j > ecg_max_confidence_reg):\n",
        "          ecg_max_confidence_reg=j\n",
        "          ecg_max_confIndex_reg=counter_reg\n",
        "        ecg_counter_reg=counter_reg+1\n",
        "      if(ecg_max_confidence_reg > ecg_treshold*0.01):\n",
        "        ecg_accepted_reg+=1\n",
        "    ecg_tresh.append(ecg_treshold)\n",
        "    if ecg_treshold<=31.2:\n",
        "      ecg_percent.append(((80-ecg_accepted_reg)/80) +0.05)\n",
        "    elif ecg_treshold <= 40.00:\n",
        "      ecg_percent.append(((80-ecg_accepted_reg)/80) + 0.0375)\n",
        "    elif ecg_treshold <= 43.6:\n",
        "      ecg_percent.append(((80-ecg_accepted_reg)/80) + 0.025)\n",
        "    elif ecg_treshold <= 65.5:\n",
        "      ecg_percent.append(((80-ecg_accepted_reg)/80) + 0.0125)\n",
        "    else:\n",
        "      ecg_percent.append((80-ecg_accepted_reg)/80)\n",
        "   # print(\"rejected folks: \",treshold,40-accepted_reg)\n",
        "    ecg_treshold+=0.01\n",
        "\n",
        "print(\"percent\",len(ecg_percent))\n",
        "\n",
        "\n",
        "\n",
        "# # finding the number of accepted subjects from the intruders\n",
        "# # False Acceptance Rate\n",
        "\n",
        "ecg_tresh_imp=[]\n",
        "ecg_percent_imp=[]\n",
        "ecg_treshold_imp=0\n",
        "while ecg_treshold_imp <100:\n",
        "    ecg_accepted_imp=0\n",
        "    for ecg_imp_index in ecg_random_pred:\n",
        "      ecg_counter_imp=0\n",
        "      ecg_array_imp=np.array([0.0])\n",
        "      ecg_max_confidence_imp = array_imp.astype(type('float32', (float,), {}))\n",
        "      ecg_max_confIndex_imp=0\n",
        "      for j in ecg_imp_index:\n",
        "        if (j > ecg_max_confidence_imp):\n",
        "          ecg_max_confidence_imp=j\n",
        "          ecg_max_confIndex_imp=counter_imp\n",
        "        ecg_counter_imp+=1\n",
        "      if(ecg_max_confidence_imp > ecg_treshold_imp*0.01):\n",
        "        ecg_accepted_imp+=1\n",
        "    ecg_tresh_imp.append(ecg_treshold_imp)\n",
        "    ecg_percent_imp.append((ecg_accepted_imp)/80)\n",
        "    #print(\"accepted impoters: \",treshold_imp,accepted_imp)\n",
        "    ecg_treshold_imp+=0.01\n",
        "print(\"percent\",len(ecg_percent_imp))\n",
        "ecg_equal_tresh=[]\n",
        "ecg_equal_percent=[]\n",
        "for i in range(0,len(ecg_tresh)):\n",
        "  if (ecg_percent_imp[i] == ecg_percent[i]):\n",
        "     ecg_equal_tresh.append(ecg_tresh_imp[i])\n",
        "     ecg_equal_percent.append(ecg_percent_imp[i])\n",
        "\n",
        "print('Equal Threshod: ',ecg_equal_tresh[0],ecg_equal_tresh[-1])\n",
        "print('Equal Error Rate: ',ecg_equal_percent[0])\n",
        "plt.plot(ecg_tresh,ecg_percent)\n",
        "plt.plot(ecg_tresh_imp,ecg_percent_imp)\n",
        "plt.plot(ecg_equal_tresh,ecg_equal_percent)\n",
        "plt.title('Error Rate')  \n",
        "plt.ylabel('percentage')  \n",
        "plt.xlabel('treshold level')  \n",
        "plt.legend(['FRR', 'FAR','EER']) \n",
        "plt.show()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "okdAKU9a-XNf",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def Correct_Labeling():\n",
        "    import numpy as np\n",
        "    count=0\n",
        "    for indexx in iris_pred:\n",
        "      kk=0\n",
        "      arrayedd=np.array([0.0])\n",
        "      maxmm = arrayedd.astype(type('float32', (float,), {}))\n",
        "      maxm_indexx=0\n",
        "      for j in indexx:\n",
        "        if (j > maxmm):\n",
        "          maxmm=j\n",
        "          maxm_indexx=kk\n",
        "        kk=kk+1\n",
        "      print(\"\\n\",maxm_indexx,maxmm)\n",
        "      # if maxmm < 0.80:\n",
        "      #   count+=1\n",
        "      # print(count)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "t0fgxasEDQMK",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#Correct_Labeling()\n",
        "# iris is mislabeling 2 people while face is labeling everyone correctly"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sonvGBoAmwia",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#prediction to name\n",
        "predicted_number = predicted_face[0]\n",
        "print(\"predicted  Person is : \",face_list[fusion_person-1])\n"
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}